﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Globalization;
using System.Linq;
using System.Resources;
using System.Threading;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Ryder_US_Website.BUS;

namespace Ryder_US_Website.Presentation.Guest
{
    public partial class Guest : System.Web.UI.MasterPage
    {
        ResourceManager rm;
        CultureInfo ci;
        protected void Page_Load(object sender, EventArgs e)
        {
            //CultureInfo ci;
            if (Session["Location"] == null)
            {
                Session["Location"] = "vi-VN";
            }
            Thread.CurrentThread.CurrentCulture = new CultureInfo(Session["Location"].ToString());
            rm = new ResourceManager("Resources.SitMap", System.Reflection.Assembly.Load("App_GlobalResources"));
            ci = Thread.CurrentThread.CurrentCulture;
            LoadString(ci);
            Session["Lang"] = Session["Location"].ToString().Substring(0, 2);

            //if(Session["RUS_Customer"]!=null)
            //{
            //    lblDangNhap.Text = "Danh mục cá nhân";
            //}
        }

        protected void btnDangNhap_Click(object sender, EventArgs e)
        {
            String username = txtTenDangNhap.Text;
            String password = txtMatKhau.Text;
            try
            {
                RUS_Customer cus = CustomerBUS.Login(username, password);
                Session.Add("RUS_Customer", cus);
                lblErrorLogin.Visible = false;
                Page_Load(sender, e);

            } catch(Exception ex)
            {
                lblErrorLogin.Visible = true;
                Utils.UtilHelpers.ShowMessage(ex.Message);
            }
        }

        protected void LinkButtonLogOut_Click(object sender, EventArgs e)
        {
            Session["RUS_Customer"]=null;
            Response.Redirect("TrangChu.aspx");
        }

        public void LoadString(CultureInfo ci)
        {
            lbHome.Text = rm.GetString("Home", ci);
            lbAbout.Text = rm.GetString("About", ci);
            lbService.Text = rm.GetString("Service", ci);
            if (Session["Location"].Equals("vi-VN"))
            {
                lbTracking1.Text = rm.GetString("Tracking", ci);
            }
            else
            {
                lbTracking.Text = rm.GetString("Tracking", ci);
            }
            lbContact.Text = rm.GetString("Contact", ci);
            lbHTKH.Text = rm.GetString("SupCus", ci);
            lbHTKT.Text = rm.GetString("Sup", ci);
            lbHTTT.Text = rm.GetString("SupOn", ci);
            lbInfo.Text = rm.GetString("Info", ci);
            lbMatKhau.Text = rm.GetString("Password", ci);
            lbQuangCao.Text = rm.GetString("Ad", ci);
            lbTenDangNhap.Text = rm.GetString("Username", ci);
            lbTracking2.Text = rm.GetString("Tracking", ci);
            lblDangNhap.Text = rm.GetString("Login", ci);
            LinkButtonLogOut.Text = rm.GetString("Logout", ci);
            btnDangNhap.Text = rm.GetString("Log", ci);
            lblLogin.Text = rm.GetString("Acc", ci);
        }

        
        protected void LinkButtonVN_Click1(object sender, EventArgs e)
        {
            Session["Location"] = "vi-VN";
            ci = new CultureInfo(Session["Location"].ToString());
            ////Thread.CurrentThread.CurrentCulture = new CultureInfo(Session["Location"].ToString());
            ////rm = new ResourceManager("Resources.SitMap", System.Reflection.Assembly.Load("App_GlobalResources"));
            ////CultureInfo ci = Thread.CurrentThread.CurrentCulture;
            LoadString(ci);
            Session["Lang"] = Session["Location"].ToString().Substring(0, 2);
        }

        protected void LinkButtonEN_Click(object sender, EventArgs e)
        {
            Session["Location"] = "en-US";
            ci = new CultureInfo(Session["Location"].ToString());
            //Thread.CurrentThread.CurrentCulture = new CultureInfo(Session["Location"].ToString());
            //rm = new ResourceManager("Resources.SitMap", System.Reflection.Assembly.Load("App_GlobalResources"));
            //CultureInfo ci = Thread.CurrentThread.CurrentCulture;
            LoadString(ci);
            Session["Lang"] = Session["Location"].ToString().Substring(0, 2);
        }

    }
}
